package com.neusoft.nepa.entity;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 独立实现的AdminData类（移除原始数据参数）
 * 仅保留JavaFX可观察属性及表格绑定功能
 */
public class AdminData implements Serializable {
    // JavaFX可观察属性（表格绑定核心）

    private final SimpleIntegerProperty indexColumn = new SimpleIntegerProperty();
    private final SimpleStringProperty feedbackName = new SimpleStringProperty();
    private final SimpleStringProperty withinProvince = new SimpleStringProperty();
    private final SimpleStringProperty withinCity = new SimpleStringProperty();
    private final SimpleStringProperty feedbackDate = new SimpleStringProperty();
    private final SimpleStringProperty feedbackTime = new SimpleStringProperty();
    private final SimpleStringProperty previewIndex = new SimpleStringProperty();
    private final SimpleStringProperty hyperlink = new SimpleStringProperty();
    private String info;

    /**
     * 构造函数（移除所有原始数据参数，使用默认初始化）
     */
    public AdminData() {
        // 初始化可观察属性（设置默认值，避免空值）
        this.previewIndex.set("未设置编号");
        this.withinProvince.set("未设置省份");
        this.withinCity.set("未设置城市");
        this.feedbackDate.set("无日期");
        this.feedbackTime.set("无时间");
        this.feedbackName.set("无反馈名称");
        this.hyperlink.set("查看 操作");
    }

    /**
     * 带参数的构造函数（可选，用于初始化特定属性）
     */
    public AdminData(String feedbackName, String withinProvince, String withinCity,
                     String previewIndex, String feedbackDate, String feedbackTime, String info) {
        this(); // 调用无参构造设置默认值
        this.indexColumn.set(0);
        this.feedbackName.set(feedbackName);
        this.withinProvince.set(withinProvince);
        this.withinCity.set(withinCity);
        this.previewIndex.set(previewIndex);
        this.feedbackDate.set(feedbackDate);
        this.feedbackTime.set(feedbackTime);
        this.hyperlink.set("操作");
        this.info = info;
    }


    // ===================== JavaFX可观察属性方法 =====================
    public SimpleIntegerProperty indexColumnProperty() {
        return indexColumn;
    }

    public StringProperty feedbackNameProperty() {
        return feedbackName;
    }

    public StringProperty withinProvinceProperty() {
        return withinProvince;
    }

    public StringProperty withinCityProperty() {
        return withinCity;
    }

    public StringProperty feedbackDateProperty() {
        return feedbackDate;
    }

    public StringProperty feedbackTimeProperty() {
        return feedbackTime;
    }

    public StringProperty previewIndexProperty() {
        return previewIndex;
    }

    public StringProperty hyperlinkProperty() {
        return hyperlink;
    }


    // ===================== 普通getter/setter =====================
    public int getIndexColumn() {
        return indexColumn.get();
    }

    public void setIndexColumn(int indexColumn) {
        this.indexColumn.set(indexColumn);
    }

    public String getFeedbackName() {
        return feedbackName.get();
    }

    public void setFeedbackName(String feedbackName) {
        this.feedbackName.set(feedbackName);
    }

    public String getWithinProvince() {
        return withinProvince.get();
    }

    public void setWithinProvince(String withinProvince) {
        this.withinProvince.set(withinProvince);
    }

    public String getWithinCity() {
        return withinCity.get();
    }

    public void setWithinCity(String withinCity) {
        this.withinCity.set(withinCity);
    }

    public String getFeedbackDate() {
        return feedbackDate.get();
    }

    public void setFeedbackDate(String feedbackDate) {
        this.feedbackDate.set(feedbackDate);
    }

    public String getFeedbackTime() {
        return feedbackTime.get();
    }

    public void setFeedbackTime(String feedbackTime) {
        this.feedbackTime.set(feedbackTime);
    }

    public String getPreviewIndex() {
        return previewIndex.get();
    }

    public void setPreviewIndex(String previewIndex) {
        this.previewIndex.set(previewIndex);
    }

    public String getHyperlink() {
        return hyperlink.get();
    }

    public void setHyperlink(String hyperlink) {
        this.hyperlink.set(hyperlink);
    }

    public String getInfo(){return this.info;}

    public void setInfo(String info){this.info = info;}

    // ===================== 日期格式化工具方法 =====================
    private String formatDate(Date date) {
        if (date == null) return "无日期";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    private String formatTime(Date date) {
        if (date == null) return "无时间";
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(date);
    }


}